/********************************************************************
* @copyright: Metanergy Technology R&D Co., Ltd
* @filename : myg0025_comp.h
* @brief    : API file of comp module
* @Author   : AE Team
********************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MYG0025_COMP_H
#define __MYG0025_COMP_H


#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "myg0025.h"

/** @addtogroup COMP
  * @{
  */

/** @defgroup COMP_Exported_Types COMP_Exported_Types
  * @{
  */

/**
  * @brief COMP Init structure definition
  */
typedef struct
{
    uint32_t PowerMode;         /*!< select power mode
                                COMP1_FULL_POWER/COMP1_LOW_POWER
                                COMP2_FULL_POWER/COMP2_LOW_POWER
                                COMP3_FULL_POWER/COMP3_LOW_POWER
                                COMP4_FULL_POWER/COMP4_LOW_POWER
                                */
    uint32_t COMPNInSel;        /*!< select negative terminal
                                COMP1_INPUT_NEGATIVE_PA10/COMP1_INPUT_NEGATIVE_PC8/COMP1_INPUT_NEGATIVE_DAC1_VOUT
                                COMP2_INPUT_NEGATIVE_PA10/COMP2_INPUT_NEGATIVE_PC9/COMP2_INPUT_NEGATIVE_DAC1_VOUT
                                COMP3_INPUT_NEGATIVE_PA10/COMP3_INPUT_NEGATIVE_PC10/COMP3_INPUT_NEGATIVE_DAC1_VOUT
                                COMP4_INPUT_NEGATIVE_PA10/COMP4_INPUT_NEGATIVE_PC11/COMP4_INPUT_NEGATIVE_DAC1_VOUT
                                */
    uint32_t COMPPInSel;        /*!< select positive terminal
                                COMP1_INPUT_POSITIVE_PA14/COMP1_INPUT_POSITIVE_PA6
                                COMP2_INPUT_POSITIVE_PA14/COMP2_INPUT_POSITIVE_PA7
                                COMP3_INPUT_POSITIVE_PA14/COMP3_INPUT_POSITIVE_PA8
                                COMP4_INPUT_POSITIVE_PA14/COMP4_INPUT_POSITIVE_PA9
                                */
    uint32_t WndwEn;            /*!< select window mode
                                COMP1_WINDOWOUT_DISABLE/COMP1_WINDOWOUT_ENABLE
                                COMP2_WINDOWOUT_DISABLE/COMP2_WINDOWOUT_ENABLE
                                */
    uint32_t OutputPolarity;    /*!< select Output Polarity
                                COMP1_OUTPUTPOL_NONINVERTED/COMP1_OUTPUTPOL_INVERTED
                                COMP2_OUTPUTPOL_NONINVERTED/COMP2_OUTPUTPOL_INVERTED
                                COMP3_OUTPUTPOL_NONINVERTED/COMP3_OUTPUTPOL_INVERTED
                                COMP4_OUTPUTPOL_NONINVERTED/COMP4_OUTPUTPOL_INVERTED
                                */
    uint32_t Hysteresis;        /*!< select Output Polarity
                                COMP1_HYSTERESIS_DISABLE/COMP1_HYSTERESIS_LEVEL1/COMP1_HYSTERESIS_LEVEL2/COMP1_HYSTERESIS_LEVEL3
                                COMP2_HYSTERESIS_DISABLE/COMP2_HYSTERESIS_LEVEL1/COMP2_HYSTERESIS_LEVEL2/COMP2_HYSTERESIS_LEVEL3
                                COMP3_HYSTERESIS_DISABLE/COMP3_HYSTERESIS_LEVEL1/COMP3_HYSTERESIS_LEVEL2/COMP3_HYSTERESIS_LEVEL3
                                COMP4_HYSTERESIS_DISABLE/COMP4_HYSTERESIS_LEVEL1/COMP4_HYSTERESIS_LEVEL2/COMP4_HYSTERESIS_LEVEL3
                                */
} COMP_InitTypeDef;
/**
  * @}
  */

/** @defgroup COMP_Define COMP_Define
  * @{
  */

/*********************************COMP definition***************************************/
#define COMP1                                 1
#define COMP2                                 2
#define COMP3                                 3
#define COMP4                                 4

/*****************************************************************************************************/

/*********************************COMP Hysteresis Configuration***************************************/
#define COMP1_HYSTERESIS_DISABLE             ((uint32_t)0x00000000U<<COMP_CSR1_COMP1HYST_Pos)
#define COMP1_HYSTERESIS_LEVEL1              ((uint32_t)0x00000001U<<COMP_CSR1_COMP1HYST_Pos)
#define COMP1_HYSTERESIS_LEVEL2              ((uint32_t)0x00000002U<<COMP_CSR1_COMP1HYST_Pos)
#define COMP1_HYSTERESIS_LEVEL3              ((uint32_t)0x00000003U<<COMP_CSR1_COMP1HYST_Pos)

#define COMP2_HYSTERESIS_DISABLE             ((uint32_t)0x00000000U<<COMP_CSR1_COMP2HYST_Pos)
#define COMP2_HYSTERESIS_LEVEL1              ((uint32_t)0x00000001U<<COMP_CSR1_COMP2HYST_Pos)
#define COMP2_HYSTERESIS_LEVEL2              ((uint32_t)0x00000002U<<COMP_CSR1_COMP2HYST_Pos)
#define COMP2_HYSTERESIS_LEVEL3              ((uint32_t)0x00000003U<<COMP_CSR1_COMP2HYST_Pos)

#define COMP3_HYSTERESIS_DISABLE             ((uint32_t)0x00000000U<<COMP_CSR2_COMP3HYST_Pos)
#define COMP3_HYSTERESIS_LEVEL1              ((uint32_t)0x00000001U<<COMP_CSR2_COMP3HYST_Pos)
#define COMP3_HYSTERESIS_LEVEL2              ((uint32_t)0x00000002U<<COMP_CSR2_COMP3HYST_Pos)
#define COMP3_HYSTERESIS_LEVEL3              ((uint32_t)0x00000003U<<COMP_CSR2_COMP3HYST_Pos)

#define COMP4_HYSTERESIS_DISABLE             ((uint32_t)0x00000000U<<COMP_CSR2_COMP4HYST_Pos)
#define COMP4_HYSTERESIS_LEVEL1              ((uint32_t)0x00000001U<<COMP_CSR2_COMP4HYST_Pos)
#define COMP4_HYSTERESIS_LEVEL2              ((uint32_t)0x00000002U<<COMP_CSR2_COMP4HYST_Pos)
#define COMP4_HYSTERESIS_LEVEL3              ((uint32_t)0x00000003U<<COMP_CSR2_COMP4HYST_Pos)
/******************************************************************************************************/

/*********************************COMP OutputPolarity Configuration***************************************/
#define COMP1_OUTPUTPOL_NONINVERTED          ((uint32_t)0x00000000U<<COMP_CSR1_COMP1POL_Pos)
#define COMP1_OUTPUTPOL_INVERTED             ((uint32_t)0x00000001U<<COMP_CSR1_COMP1POL_Pos)

#define COMP2_OUTPUTPOL_NONINVERTED          ((uint32_t)0x00000000U<<COMP_CSR1_COMP2POL_Pos)
#define COMP2_OUTPUTPOL_INVERTED             ((uint32_t)0x00000001U<<COMP_CSR1_COMP2POL_Pos)

#define COMP3_OUTPUTPOL_NONINVERTED          ((uint32_t)0x00000000U<<COMP_CSR2_COMP3POL_Pos)
#define COMP3_OUTPUTPOL_INVERTED             ((uint32_t)0x00000001U<<COMP_CSR2_COMP3POL_Pos)

#define COMP4_OUTPUTPOL_NONINVERTED          ((uint32_t)0x00000000U<<COMP_CSR2_COMP4POL_Pos)
#define COMP4_OUTPUTPOL_INVERTED             ((uint32_t)0x00000001U<<COMP_CSR2_COMP4POL_Pos)
/******************************************************************************************************/

/*********************************COMP PowerMode Configuration***************************************/
#define COMP1_FULL_POWER                     ((uint32_t)0x00000000U<<COMP_CSR1_COMP1MODE_Pos)
#define COMP1_LOW_POWER                      ((uint32_t)0x00000001U<<COMP_CSR1_COMP1MODE_Pos)

#define COMP2_FULL_POWER                     ((uint32_t)0x00000000U<<COMP_CSR1_COMP2MODE_Pos)
#define COMP2_LOW_POWER                      ((uint32_t)0x00000001U<<COMP_CSR1_COMP2MODE_Pos)

#define COMP3_FULL_POWER                     ((uint32_t)0x00000000U<<COMP_CSR2_COMP3MODE_Pos)
#define COMP3_LOW_POWER                      ((uint32_t)0x00000001U<<COMP_CSR2_COMP3MODE_Pos)

#define COMP4_FULL_POWER                     ((uint32_t)0x00000000U<<COMP_CSR2_COMP4MODE_Pos)
#define COMP4_LOW_POWER                      ((uint32_t)0x00000001U<<COMP_CSR2_COMP4MODE_Pos)
/******************************************************************************************************/

/*********************************COMP WINDOWMODE Configuration***************************************/
#define COMP1_WINDOWOUT_DISABLE              ((uint32_t)0x00000000U<<COMP_CSR1_WNDWEN1_Pos)
#define COMP1_WINDOWOUT_ENABLE               ((uint32_t)0x00000001U<<COMP_CSR1_WNDWEN1_Pos)

#define COMP2_WINDOWOUT_DISABLE              ((uint32_t)0x00000000U<<COMP_CSR1_WNDWEN2_Pos)
#define COMP2_WINDOWOUT_ENABLE               ((uint32_t)0x00000001U<<COMP_CSR1_WNDWEN2_Pos)

/******************************************************************************************************/

/*********************************COMP INPUT PLUS and MINUS Configuration******************************/
#define COMP1_INPUT_POSITIVE_PA14                ((uint32_t)0x00000000U<<COMP_CSR1_COMP1PINSEL_Pos)
#define COMP1_INPUT_POSITIVE_PA6                 ((uint32_t)0x00000001U<<COMP_CSR1_COMP1PINSEL_Pos)
#define COMP1_INPUT_NEGATIVE_PA10               ((uint32_t)0x00000000U<<COMP_CSR1_COMP1NINSEL_Pos)
#define COMP1_INPUT_NEGATIVE_PC8                ((uint32_t)0x00000001U<<COMP_CSR1_COMP1NINSEL_Pos)
#define COMP1_INPUT_NEGATIVE_DAC1_VOUT          ((uint32_t)0x00000002U<<COMP_CSR1_COMP1NINSEL_Pos)

#define COMP2_INPUT_POSITIVE_PA14                ((uint32_t)0x00000000U<<COMP_CSR1_COMP2PINSEL_Pos)
#define COMP2_INPUT_POSITIVE_PA7                 ((uint32_t)0x00000001U<<COMP_CSR1_COMP2PINSEL_Pos)
#define COMP2_INPUT_NEGATIVE_PA10               ((uint32_t)0x00000000U<<COMP_CSR1_COMP2NINSEL_Pos)
#define COMP2_INPUT_NEGATIVE_PC9                ((uint32_t)0x00000001U<<COMP_CSR1_COMP2NINSEL_Pos)
#define COMP2_INPUT_NEGATIVE_DAC1_VOUT          ((uint32_t)0x00000002U<<COMP_CSR1_COMP2NINSEL_Pos)

#define COMP3_INPUT_POSITIVE_PA14                ((uint32_t)0x00000000U<<COMP_CSR2_COMP3PINSEL_Pos)
#define COMP3_INPUT_POSITIVE_PA8                 ((uint32_t)0x00000001U<<COMP_CSR2_COMP3PINSEL_Pos)
#define COMP3_INPUT_NEGATIVE_PA10               ((uint32_t)0x00000000U<<COMP_CSR2_COMP3NINSEL_Pos)
#define COMP3_INPUT_NEGATIVE_PC10               ((uint32_t)0x00000001U<<COMP_CSR2_COMP3NINSEL_Pos)
#define COMP3_INPUT_NEGATIVE_DAC1_VOUT          ((uint32_t)0x00000002U<<COMP_CSR2_COMP3NINSEL_Pos)

#define COMP4_INPUT_POSITIVE_PA14                ((uint32_t)0x00000000U<<COMP_CSR2_COMP4PINSEL_Pos)
#define COMP4_INPUT_POSITIVE_PA9                 ((uint32_t)0x00000001U<<COMP_CSR2_COMP4PINSEL_Pos)
#define COMP4_INPUT_NEGATIVE_PA10               ((uint32_t)0x00000000U<<COMP_CSR2_COMP4NINSEL_Pos)
#define COMP4_INPUT_NEGATIVE_PC11               ((uint32_t)0x00000001U<<COMP_CSR2_COMP4NINSEL_Pos)
#define COMP4_INPUT_NEGATIVE_DAC1_VOUT          ((uint32_t)0x00000002U<<COMP_CSR2_COMP4NINSEL_Pos)
/******************************************************************************************************/


/**
  * @}
  */

/**
  * @}
  */

void COMP_SetInputNonInverting(uint8_t COMPx, uint32_t InputNonInverting);
uint32_t COMP_GetInputNonInverting(uint8_t COMPx);
void COMP_SetInputInverting(uint8_t COMPx, uint32_t InputInverting);
uint32_t COMP_GetInputInverting(uint8_t COMPx);
void COMP_SetCommonWindowMode(uint8_t COMPx, uint32_t WindowMode);
uint32_t COMP_GetCommonWindowMode(uint8_t COMPx);
void COMP_SetPowerMode(uint8_t COMPx, uint32_t PowerMode);
uint32_t COMP_GetPowerMode(uint8_t COMPx);
void COMP_SetOutputPolarity(uint8_t COMPx, uint32_t OutputPolarity);
uint32_t COMP_GetOutputPolarity(uint8_t COMPx);
void COMP_SetHysteresis(uint8_t COMPx, uint32_t Hysteresis);
uint32_t COMP_GetHysteresis(uint8_t COMPx);
void COMP_Enable(uint8_t COMPx);
void COMP_Disable(uint8_t COMPx);
uint32_t COMP_IsEnabled(uint8_t COMPx);
void COMP_Lock(uint8_t COMPx);
uint32_t COMP_IsLocked(uint8_t COMPx);
uint32_t COMP_ReadOutputLevel(uint8_t COMPx);
void COMP_DeInit(void);
void COMP_SetWndwEn(uint32_t WindowMode);
uint32_t COMP_GetWndwEn(uint8_t COMPx);
void COMP_SetFilerEnable(uint8_t COMPx);
void COMP_SetFilerDisable(uint8_t COMPx);
void COMP_SetFilerCnt(uint16_t FilerCLKCnt);


void COMP_StructInit(COMP_InitTypeDef *COMP_InitStruct);
ErrorStatus COMP_Init(uint8_t COMPx, COMP_InitTypeDef *COMP_InitStruct);


#ifdef __cplusplus
}
#endif

#endif /* __MYG0025_COMP_H */

